<template>
    <div id="page-message-center">
        <div class="list_breadcrumb">位置：消息中心</div>
        <div class="list_center">
            <!-- 用户有消息 -->
            <ul v-if="this.listShow">
                <li @click="goDetail(item.id,item.pushTime)" v-for="(item,index) in listData" :key="index">
                    <span v-if="item.isRead" class="news_title read">{{ item.title }}</span>
                    <span v-else class="news_title unread">{{ item.title }}</span>
                    <span class="news_time">{{ item.createTime.substring(0, 10) }}</span>
                </li>
            </ul>
            <!-- 用户无消息 -->
            <div v-else class="no_news">没有消息</div>
            <el-pagination
                v-show="this.listShow"
                class="paging"
                background
                layout="prev, pager, next"
                :total="listDotal"
                @current-change="handleCurrentChange"
            ></el-pagination>
        </div>
    </div>
</template>

<script>
export default {
    name: "messageCenter",
    data() {
        return {
            listDotal: 0,
            listShow: true,
            listData: ""
        };
    },
    methods: {
        // 获取消息列表
        getNoticeData(data) {
            this.$request.notice(data).then(res => {
                console.log(res);
                if (res.status == 200) {
                    console.log(this.listDotal);
                    this.listDotal = res.data.total;
                    this.listDotal == 0
                        ? (this.listShow = false)
                        : (this.listShow = true);
                    this.listData = res.data.list;
                } else {
                    this.requestError(res.status, res.message)
                }
            }, err => {
                console.log(err);
                this.requestFail(err);
            });
        },
        goDetail(id,time) {
            let data = {
                id: id
            };
            this.$request.read(data).then(res => {
                console.log('推送消息已读',res);
                if (res.status == 200) {
                    console.log('标为已读')
                } else {
                    this.requestError(res.status, res.message)
                }
            }, err => {
                console.log(err);
                this.requestFail(err);
            });
            if(time){
                this.$router.push({
                    name: "personal-message-detail",
                    query: {id,time}
                });
            }else {
                this.$router.push({
                    path: '/search/subscribe'
                });
            }
            
        },
        // 翻页
        handleCurrentChange(val) {
            console.log(val);
            let listData = {
                page: val,
                size: 10
            };
            this.getNoticeData(listData);
        }
    },
    mounted() {
        let listData = {
            page: 1,
            size: 10
        };
        this.getNoticeData(listData);
    }
};
</script>

<style scoped>
.list_breadcrumb {
    width: 100%;
    font-size: 16px;
    font-weight: normal;
    font-stretch: normal;
    letter-spacing: 2px;
    color: #252627;
    background: #ffffff;
    line-height: 58px;
    padding-left: 20px;
}

.list_center {
    width: 100%;
    margin-top: 10px;
    background: #ffffff;
    overflow: hidden;
}

.list_center li {
    border-bottom: solid 1px #e6e6e6;
    cursor: pointer;
}

.no_news {
    text-align: center;
    line-height: 100px;
    font-size: 40px;
}

.list_center li .news_title {
    font-size: 18px;
    font-weight: normal;
    font-stretch: normal;
    line-height: 30px;
    letter-spacing: 0px;
    display: inline-block;
    padding-left: 22px;
    line-height: 78px;
    width: 745px;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    word-break: break-all;
    vertical-align: middle;
}

.list_center li .unread {
    color: #252627;
}

.list_center li .read {
    color: #888888;
}

.list_center li .news_time {
    vertical-align: middle;
    float: right;
    padding-right: 22px;
    font-size: 18px;
    font-weight: normal;
    font-stretch: normal;
    line-height: 78px;
    letter-spacing: 0px;
    color: #888888;
}

.list_center li:hover {
    background: #ececec;
}

.paging {
    float: right;
    margin: 26px 20px 60px 0;
}
</style>